﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;

namespace ViewMaker.Core.Controls
{
    /// <summary>
    /// ボタンViewコントロール
    /// </summary>
    public class ButtonViewControl : ControlViewControl
    {
        /// <summary>
        /// プロパティ定数
        /// </summary>
        public new class Properties : ControlViewControl.Properties
        {
            public const string ImageSource = "ImageSource";
        }

        /// <summary>
        /// イメージのソース
        /// </summary>
        [Display(Name = "Image Source")]
        public string ImageSource { get; set; }

        public ButtonViewControl()
        {
            ControlType = ViewControlType.Button;
            RowSpan = 1;
        }

        /// <summary>
        /// Xamlを生成する
        /// </summary>
        /// <param name="parent"></param>
        /// <returns></returns>
        public override List<XamlNode> CreateXaml(XamlNode parent)
        {
            var list = new List<XamlNode>();
            var node = parent.CreateElement("Button");
            if (!string.IsNullOrEmpty(ImageSource))
            {
                node.AddElement("Image").SetAttribute("Source",ImageSource );
            }
            else
            {
                node.InnerText = Item.Caption;
            }
            SetBindingAttribute(node, "Command", Item.BindPath, true);
            ApplyBaseProperty(node);
            list.Add(node);
            return list;
        }
    }

}
